After virtualization technologies are developed, multiple virtual machines (VM) coexist in one host (Host, also referred to as a physical host hereinafter). A virtual machine is presented as a normal physical machine to a user, and therefore, in addition to a data switching requirement between virtual machines, there is a communication requirement between a virtual machine and an external network.
Currently, mainstream data switching solutions for a virtual machine include virtual switching and physical switching, where the virtual switching refers to a behavior of simulating a physical switch using software, which is relatively complex to implement; and the physical switching refers to a behavior of implementing switching logic on a chip of a network interface card (NIC) or using a physical switch, that is, external data switching of a virtual machine occurs on hardware. For example, a device pass-through technology may be used to directly allocate a physical NIC port to a virtual machine, or a virtual function (VF) generated by a Single Root Input/Output Virtualization (SR-IOV) NIC (wherein the VF is a virtual device simulated by an SR-IOV device) is used to enable a virtual machine to directly use a NIC, so that data switching may occur on a physical switch or a switching logic module on a NIC. The solution can eliminate consumption of a host caused by use of a network by a virtual machine, and has relatively desirable performance; moreover, a Layer 2 switch (L2 switch) inside a NIC queries a media access control (MAC) address forwarding of an internal VF, and there is no logical loop, so that an overhead of Spanning Tree Protocol (STP) is avoided, and implementation is relatively flexible.
During research on and practice of the prior art, the inventor of the present invention finds that although such an existing physical switching solution has improved performance and flexibility compared with virtual switching, data switching efficiency of the physical switching solution is still not high enough. For example, all virtual machine communication needs to pass through a NIC first, and both communication with a unit inside a host and communication with a device outside the host consume Peripheral Component Interconnect (PCI) bus bandwidth, and the like. Moreover, in the solution, communication between virtual machines inside a host further affects communication between another virtual machine inside the host and a device outside the host.